package com.example;

import java.sql.SQLException;
import java.util.List;

public class AssignClassesMavenHelper {

    public static void main(String[] args) {
        UserDAO userDAO = new UserDAO();
        try {
            List<User> users = userDAO.getAllUsers();
            System.out.println("Fetched all users.");
            
            // Assign students to sample classes
            int class1Count = 0;
            int class2Count = 0;
            int class3Count = 0;
            
            for (User user : users) {
                if ("student".equals(user.getType())) {
                    if (class1Count < 2) { // Assign first 2 students to class 1
                        user.setDepartment("软件工程1班");
                        userDAO.updateUser(user);
                        System.out.println("Assigned student " + user.getUsername() + " to 软件工程1班");
                        class1Count++;
                    } else if (class2Count < 2) { // Assign next 2 students to class 2
                        user.setDepartment("计算机科学2班");
                        userDAO.updateUser(user);
                        System.out.println("Assigned student " + user.getUsername() + " to 计算机科学2班");
                        class2Count++;
                    } else if (class3Count < 2) {
                         // Assign next 2 students to class 3
                         user.setDepartment("信息管理3班");
                         userDAO.updateUser(user);
                         System.out.println("Assigned student " + user.getUsername() + " to 信息管理3班");
                         class3Count++;
                    } else {
                        // Assign remaining students to a default class or leave as is
                        user.setDepartment("未知班级");
                        userDAO.updateUser(user);
                        System.out.println("Assigned student " + user.getUsername() + " to 未知班级");
                    }
                }
            }
            System.out.println("Finished assigning classes to students.");

        } catch (SQLException e) {
            e.printStackTrace();
            System.err.println("Database error assigning classes.");
        }
    }
} 